package edu.nf.relaxenjoy.web.controller.app;

import edu.nf.relaxenjoy.common.result.ResultVO;
import edu.nf.relaxenjoy.service.MinioService;
import edu.nf.relaxenjoy.web.controller.BaseController;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartRequest;

import java.util.List;

/**
 * @author zhu
 * @date 2024-12-24
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/util/fileminio")
public class MinioController extends BaseController {

    private final MinioService minioService;

    /**
     * 上传文件
     *
     * @param file 要上传的文件，类型为 {@link MultipartFile}。
     * @return
     */
    @PostMapping("uploadFile")
    public ResultVO uploadFile(MultipartFile file) {
        return success(minioService.uploadFile(file));
    }

    /**
     * 批量上传文件
     *
     * @param request
     * @param num
     * @return
     */
    @PostMapping("uploadFiles")
    public ResultVO uploadFiles(MultipartRequest request, Integer num) {
        return success(minioService.uploadFiles(num, request));
    }

    /**
     * 删除文件
     *
     * @param fileName
     * @return
     */
    @RequestMapping("deleteFile")
    public ResultVO deleteFile(@RequestParam String fileName) {
        minioService.deleteFile(fileName);
        return success();
    }

    /**
     * 批量删除文件
     *
     * @param fileNames
     * @return
     */
    @RequestMapping("deleteFiles")
    public ResultVO deleteFiles(List<String> fileNames) {
        minioService.deleteFiles(fileNames);
        return success();
    }
}
